package com.google.code.instrumentation.util;

import javassist.ClassPool;
import javassist.CtClass;
import javassist.LoaderClassPath;
import javassist.NotFoundException;

public final class CompileTimeClassUtil {

	private CompileTimeClassUtil() {
		// prevent instantiation
	}

	public static CtClass getCtClass(final ClassLoader loader,
			final String className) throws NotFoundException {
		final ClassPool pool = ClassPool.getDefault();
		final LoaderClassPath lcp = new LoaderClassPath(loader);
		pool.appendClassPath(lcp);

		final CtClass ctClass = pool.get(className);
		return ctClass;
	}

	public static CtClass getCtClassFor(final Class<?> clazz)
			throws NotFoundException {
		final ClassPool cp = ClassPool.getDefault();
		final CtClass ctClass = cp.get(clazz.getName());
		return ctClass;
	}

}
